﻿using OnlineEducation.Data;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OnlineEducation.Constants
{

    public class CodeManager
    {
        private ApplicationDbContext _context;

        public CodeManager(ApplicationDbContext context)
        {
            _context = context;

        }

        public string GetValue(string name)
        {
            return _context.Codes.Where(n => n.Name == name).Select(n => n.Value).FirstOrDefault();
        }

    }

    public class CodeHelper
    {
        public static IEnumerable<SelectListItem> GetListItems(List<Data.Entities.Code> codes, bool appendEmpty = true)
        {
            if (appendEmpty)
            {
                codes.Add(new Data.Entities.Code { Name = "", Value = "选择一个值", Status = 1 });
            }
            return codes.Where(n => n.Status == 1).Select(n => new SelectListItem()
            {
                Text = n.Value,
                Value = n.Name
            }).OrderBy(n => n.Value);


        }


        public static IEnumerable<SelectListItem> GetListItems(IEnumerable<Data.Entities.Course> courses, bool appendEmpty = true)
        {
            List<SelectListItem> list = new List<SelectListItem>();

            if (appendEmpty)
            {
                list.Add(new SelectListItem { Value = "", Text = "选择一个值" });
            }

            list.AddRange(courses.GroupBy(n => n.Subject).SelectMany(k =>
              {
                  List<SelectListItem> newlist = new List<SelectListItem>();

                  var group = new SelectListGroup
                  {
                      Name = k.Key
                  };

                  foreach (var c in k)
                  {
                      newlist.Add(new SelectListItem
                      {
                          Group = group,
                          Text = c.Title + " - " + c.SubTitle,
                          Value = c.Id.ToString()
                      });
                  }

                  return newlist;
 
              }));
            return list;

        }

        private static SelectListGroup BuildSelectListGroup(string name, bool disabled = false)
        {
            var group = new SelectListGroup();

            group.Name = name;

            group.Disabled = disabled;

            return group;

        }

        public static IEnumerable<SelectListItem> GetListItems(List<Data.Entities.ApplicationUser> users, bool appendEmpty = true)
        {
            List<SelectListItem> list = new List<SelectListItem>();

            if (appendEmpty)
            {
                list.Add(new SelectListItem { Value = "", Text = "选择一个值" });
            }

            list.AddRange(users.Select(n => new SelectListItem()
            {
                Text = n.FullName + "(" + n.UserName + ")",
                Value = n.Id.ToString()
            }));

            return list;

        }
    }

    public class Code
    {
        public static readonly string SystemCategory = "SystemCategory";
        public static readonly string InvoiceType = "InvoiceType";
        public static readonly string DeliveryPath = "DeliveryPath";
        public static readonly string OrderCategory = "OrderCategory";

        public static readonly string Subject = "Subject";

        public static readonly string Holiday = "Holiday";


    }

    public class Status
    {
        public static readonly string Active = "A";
        public static readonly string Inactive = "I";

    }
    public class CourseStatus
    {

        public static readonly int Active = 1;
        public static readonly int Inactive = 2;

    }


    public class OrderStatus
    {
        public static readonly int New = 1;//wait for payment 
        public static readonly int Paid = 2;//buyer paid already
        public static readonly int Refund = 3;//already refund
        public static readonly int Cancelled = 4;// cancelled
        public static readonly int Exception = 5;// exception

    }

    public class ServerAPI
    {
        public const string Create = "create";
        public const string Join = "join";
        public const string IsMeetingRunning = "isMeetingRunning";
        public const string End = "end";
        public const string GetMeetingInfo = "getMeetingInfo";
        public const string GetMeetings = "getMeetings";
        public const string GetRecordings = "getRecordings";
        public const string PublishRecordings = "publishRecordings";
        public const string DeleteRecordings = "deleteRecordings";
        public const string UpdateRecording = "updateRecordings";


        public const string APIKey = "R63IxefxKHcEin4GTyInG6IrwhKWgxSJMR4DmkKI0";
    }

    public class MeetingGuestPolicy
    {
        public const string ALWAYS_ACCEP = "ALWAYS_ACCEP";
        public const string ALWAYS_DENY = "ALWAYS_DENY";
        public const string ASK_MODERATOR = "ASK_MODERATOR";
    }





}
